using System;
using System.Text;
using System.Collections;
using System.Reflection;
using SUnit.Core.SchemaClasses;

namespace SUnit.Core
{
	public class TestInfo
    {
        #region Instance variables

        private string _name;
        private Guid _fullName = Guid.NewGuid();        
        private sUnitTestCaseCase _testCase;
        private sUnitTestCase _testCaseGroup;
        private ArrayList _tests = new ArrayList();

        private MethodInfo _testMethod;

        #endregion

        #region Constructors

        public TestInfo(string name, sUnitTestCase[] testCases)
        {
            _name = name;            

            foreach (sUnitTestCase testCaseGroup in testCases)
                Tests.Add(new TestInfo(testCaseGroup));
        }

        public TestInfo(sUnitTestCase testCaseGroup)
        {
            _testCaseGroup = testCaseGroup;
            _name = testCaseGroup.functionName;            

            //Agrego los tests correspondientes a los hijos
            foreach (sUnitTestCaseCase c in testCaseGroup.cases)
                Tests.Add(new TestInfo(TestCaseGroup, c));
        }

        public TestInfo(sUnitTestCase testCaseGroup, sUnitTestCaseCase testCase)
        {
            _testCaseGroup = testCaseGroup;
            _testCase = testCase;
            _name = testCase.id;
        }

        public TestInfo(string name, Hashtable tests)
        {
            _name = name;

            foreach (string functionName in tests.Keys)
            {
                MethodInfo[] cases = (MethodInfo[])tests[functionName];

                Tests.Add(new TestInfo(functionName, cases));
            }
        }

        public TestInfo(string name, MethodInfo[] tests)
        {
            _name = name;

            foreach (MethodInfo mi in tests)
                Tests.Add(new TestInfo(mi));
        }

        public TestInfo(MethodInfo test)
        {
            _name = test.Name;
            _testMethod = test;
        }

        #endregion

        #region Public Properties

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public Guid FullName
        {
            get { return _fullName; }
            set { _fullName = value; }
        }
        
        public bool IsDynamic
        {
            get { return _testMethod!=null; }            
        }

        public bool IsSuite
        {
            get { return _tests.Count > 0; }
        }


        //public RunState RunState
        //{
        //    get { return _runState; }
        //    set { _runState = value; }
        //}

        public MethodInfo TestMethod
        {
            get { return _testMethod; }
            set { _testMethod = value; }
        }

        public ArrayList Tests
        {
            get { return _tests; }
            set { _tests = value; }
        }

        public sUnitTestCaseCase TestCase
        {
            get { return _testCase; }
        }

        public sUnitTestCase TestCaseGroup
        {
            get { return _testCaseGroup; }
        }


        #endregion

        #region Public Methods

        //public TestResult Run(Tester tester)
        //{
        //    //TODO: pensar como hacer esto
        //    TestResult result = tester.Test(_testCase, null);
            
        //    return result;
        //}

        #endregion

    }
}
